home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2017 October / PCgo 10-2017 CD-ROM Germany.iso / nw.pak / Unnamed File 005265.txt < prev    next >
Encoding:
Text File  |  2015-07-29  |  4.8 KB  |  150 lines

  1. // Copyright (c) 2012 Intel Corp
  2. // Copyright (c) 2012 The Chromium Authors
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. //  in the Software without restriction, including without limitation the rights
  7. //  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
  8. // pies of the Software, and to permit persons to whom the Software is furnished
  9. //  to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in al
  12. // l copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
  15. // PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
  16. // S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  17. //  OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
  18. // ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. //  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20.  
  21. var argv, fullArgv, dataPath, manifest;
  22. var v8_util = process.binding('v8_util');
  23.  
  24. function App() {
  25. }
  26. require('util').inherits(App, exports.Base);
  27.  
  28. App.filteredArgv = [
  29.   /^--no-toolbar$/,
  30.   /^--url=/,
  31.   /^--remote-debugging-port=/,
  32.   /^--renderer-cmd-prefix/,
  33. ];
  34.  
  35. App.prototype.quit = function() {
  36.   nw.callStaticMethod('App', 'Quit', [ ]);
  37. }
  38.  
  39. App.prototype.closeAllWindows = function() {
  40.   nw.callStaticMethod('App', 'CloseAllWindows', [ ]);
  41. }
  42.  
  43. App.prototype.crashBrowser = function() {
  44.   nw.callStaticMethod('App', 'CrashBrowser', [ ]);
  45. }
  46.  
  47. App.prototype.crashRenderer = function() {
  48.   nw.crashRenderer();
  49. }
  50.  
  51. App.prototype.setCrashDumpDir = function(dir) {
  52.   nw.setCrashDumpDir(dir); // for windows renderer process
  53.   return nw.callStaticMethodSync('App', 'SetCrashDumpDir', [ dir ]);
  54. }
  55.  
  56. App.prototype.createShortcut = function(dir) {
  57.   return nw.callStaticMethodSync('App', 'CreateShortcut', [ dir ]);
  58. }
  59.  
  60. App.prototype.clearCache = function() {
  61.   nw.callStaticMethodSync('App', 'ClearCache', [ ]);
  62. }
  63.  
  64. App.prototype.doneMenuShow = function() {
  65.   nw.callStaticMethodSync('App', 'DoneMenuShow', [ ]);
  66. }
  67.  
  68. App.prototype.getProxyForURL = function (url) {
  69.   return nw.callStaticMethodSync('App', 'getProxyForURL', [ url ]);
  70. }
  71.  
  72. App.prototype.setProxyConfig = function (proxy_config) {
  73.   return nw.callStaticMethodSync('App', 'SetProxyConfig', [ proxy_config ]);
  74. }
  75.  
  76. App.prototype.addOriginAccessWhitelistEntry = function(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains) {
  77.     return nw.callStaticMethodSync('App', 'AddOriginAccessWhitelistEntry', sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
  78. }
  79.  
  80. App.prototype.removeOriginAccessWhitelistEntry = function(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains) {
  81.     return nw.callStaticMethodSync('App', 'RemoveOriginAccessWhitelistEntry', sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);
  82. }
  83.  
  84. App.prototype.registerGlobalHotKey = function(shortcut) {
  85.   if (v8_util.getConstructorName(shortcut) != "Shortcut")
  86.     throw new TypeError("Invaild parameter, need Shortcut object.");
  87.  
  88.   return nw.callStaticMethodSync('App',
  89.                                  'RegisterGlobalHotKey',
  90.                                  [ shortcut.id ])[0];
  91. }
  92.  
  93. App.prototype.unregisterGlobalHotKey = function(shortcut) {
  94.   if (v8_util.getConstructorName(shortcut) != "Shortcut")
  95.     throw new TypeError("Invaild parameter, need Shortcut object.");
  96.  
  97.   nw.callStaticMethodSync('App', 'UnregisterGlobalHotKey', [ shortcut.id ]);
  98. }
  99.  
  100. App.prototype.__defineGetter__('argv', function() {
  101.   if (!argv) {
  102.     var fullArgv = this.fullArgv;
  103.     argv = [];
  104.     for (var i = 0; i < fullArgv.length; ++i) {
  105.       var matched = false;
  106.       for (var j = 0; j < App.filteredArgv.length; ++j) {
  107.         if (App.filteredArgv[j].test(fullArgv[i])) {
  108.           matched = true;
  109.           break;;
  110.         }
  111.       }
  112.       if (matched)
  113.         continue;
  114.  
  115.       argv.push(fullArgv[i]);
  116.     }
  117.   }
  118.  
  119.   return argv;
  120. });
  121.  
  122. App.prototype.__defineGetter__('fullArgv', function() {
  123.   if (!fullArgv)
  124.     fullArgv = nw.callStaticMethodSync('App', 'GetArgv', [ ]);
  125.  
  126.   return fullArgv;
  127. });
  128.  
  129. App.prototype.__defineGetter__('dataPath', function() {
  130.   if (!dataPath)
  131.     dataPath = nw.callStaticMethodSync('App', 'GetDataPath', [ ])[0];
  132.  
  133.   return dataPath;
  134. });
  135.  
  136. App.prototype.__defineGetter__('manifest', function() {
  137.   if (!manifest) {
  138.     manifest = JSON.parse(
  139.         nw.callStaticMethodSync('App', 'GetPackage', [ ])[0]);
  140.   }
  141.   return manifest;
  142. });
  143.  
  144. // Store App object in node's context.
  145. if (process['_nw_app']) {
  146.   exports.App = process['_nw_app'];
  147. } else {
  148.   exports.App = process['_nw_app'] = new App();
  149. }
  150.